class SessionController < ApplicationController
  def new
  end

  def create
    if user = User.authenticate(params[:name], params[:password])
      session[:user_id] = user.id
      session[:username] = user.username
      if (session[:username] == "admin")
        redirect_to admin_url
      
      else
        redirect_to admin_url
      end
    else
     redirect_to login_url, :alert => "Invalid user/password combination"
    end
  end

  def destroy
      session[:user_id] = nil
      session[:username] = nil
     redirect_to home_url, :notice => "Logged out"

  end
end
